/*
 * @project: initializr-start
 * @package: com.Rsonly.spring.cloud.weather.controller
 * @filename: WeatherReportController
 *
 * Copyright (c) 2018 eSunny Info. Tech Ltd. All rights reserved.
 *
 */
package com.Rsonly.spring.cloud.weather.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.Rsonly.spring.cloud.weather.service.CityDataService;
import com.Rsonly.spring.cloud.weather.service.WeatherReportService;

/**
 * @typename: WeatherReportController
 * @brief: 〈一句话功能简述〉
 * @author: Liqr
 * @date: 2018-08-03-0003 14:47
 * @version: 1.0.0
 * @since
 */
@RestController
@RequestMapping("/report")
public class WeatherReportController {

    @Autowired
    private CityDataService cityDataService;

    @Autowired
    private WeatherReportService weatherReportService;

    @GetMapping("/cityId/{cityId}")
    public ModelAndView getReportByCityId(@PathVariable("cityId") String cityId, Model model) throws Exception{

        model.addAttribute("title", "我的天气预报");
        model.addAttribute("cityId", cityId);
        model.addAttribute("cityList", cityDataService.listCity());
        model.addAttribute("report", weatherReportService.getDataByCityId(cityId));
        return new ModelAndView("weather/report","reportModel",model);
    }

}
